cmake_minimum_required(VERSION 3.20)

set(str "++Hello CMake 123 @a#b$c%d Hello Arch Linux 4-5/6|")

# -- 查找
# string(FIND ${str} "Hello" index)
# string(FIND ${str} "Hello" index REVERSE)
# message(STATUS "${index}")

# -- 替换
# string(REPLACE "Hello" "World" outVar ${str})
# message(STATUS "${outVar}")

# -- 正则匹配所有数字字母
# string(REGEX MATCHALL [A-Za-z0-9] outVar ${str})
# message(STATUS "${outVar}")

# -- 字节长度
# string(LENGTH ${str} len)
# message(STATUS len = "${len}")

# -- strip生成器表达式
# set(text "$<1:Hello>World")
# message(STATUS ${text})
# string(GENEX_STRIP ${text} outVar)
# message(STATUS ${outVar})

# -- 哈希
# string(MD5 result ${str})
# string(SHA256 result ${str})
# message(STATUS ${result})

# -- 数字转为对应ASCII
# set(text 65;66;67)
# string(ASCII ${text} result)
# message(STATUS ${result})

# -- 每个字节转为16进制
# set(num ABC) # 65 66 67
# string(HEX ${num} result)
# message(STATUS ${result})

# -- 随机生成指定长度
# string(RANDOM LENGTH 10 result)
# string(RANDOM LENGTH 10 ALPHABET abcde12345 result)
# message(STATUS ${result})

# -- 时间戳格式化为日期
# string(TIMESTAMP timedate)
# string(TIMESTAMP timedate "%Y-%m-%d %H:%M:%S")
# message(STATUS ${timedate})

# -- 非字母数字转为下划线
string(MAKE_C_IDENTIFIER ${str} result)
message(STATUS ${result})
